import processing.core.PApplet;
import processing.core.PConstants;


/**
 * @author Steve Duncan
 * @author Matt Sponnar
 * 
 * Creates the snowflake 
 */
public class Snowflake {	
	int numLines, peak;
	double radius[] =   {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};  //full circle to help test
	Lines[] ln;
	int[] color = new int[3];
	

	int originx, originy, wh, ww;
	PApplet parent;

	Snowflake(PApplet p, int ox, int oy, int windoww, int windowh){

		parent = p;
		originx = ox;
		originy = oy;
		wh = windowh;
		ww = windoww;
		peak = -1;
	}

	public void setup(int[] color){
		float radiusScale = 45;
		this.color = color;

		numLines = PApplet.round(PApplet.degrees(PConstants.TWO_PI)/6);
		ln = new Lines[numLines];

		for (int i = 0; i<ln.length; i++){
			float angle = PApplet.radians((i-15)*6);
			float x = (float) (ww/2 +(PApplet.cos(angle) * radius[i] * radiusScale));     	// The equation for the circle
			float y = (float) (wh/2  +(PApplet.sin(angle) * radius[i] * radiusScale));     	// that defines the lines.
			ln[i] = new Lines(x, y, originx, originy, color);
		}
	}
	
	public void setup(int[] color, int max){
		float radiusScale = 45;
		peak = max;

		numLines = PApplet.round(PApplet.degrees(PConstants.TWO_PI)/6);
		ln = new Lines[numLines];

		for (int i = 0; i<ln.length; i++){
			float angle = PApplet.radians((i-15)*6);
			float x = (float) (ww/2 +(PApplet.cos(angle) * radius[i] * radiusScale));     	// The equation for the circle
			float y = (float) (wh/2  +(PApplet.sin(angle) * radius[i] * radiusScale));     	// that defines the lines.
			
			if(i == max){
				int c[] = new int[3];
				c[0] = 0;
				c[1] = 206;
				c[2] = 209;
				ln[i] = new Lines(x, y, originx, originy, c);
			}
			else{
				ln[i] = new Lines(x, y, originx, originy, color);
			}
		}
	}

	public void setRadius(double[] radius) {
		this.radius = radius;
	}

	public void display(){

		for (int i = 0; i <ln.length; i++){
			ln[i].display();
		}
		
		parent.noFill();
		parent.ellipse(originx, originy, ww/2 + 42, wh/2 + 42);
	}

	class Lines{
		float x, y, m, ox, oy;
		int[] color = new int[3];
		Lines(float xpos, float ypos, int ox, int oy, int[] c){
			x = xpos;
			y = ypos;
			m = y/x;  // if we need slope
			this.ox = (float)ox;
			this.oy = (float)oy;
			color = c;
		}

		void display(){
			parent.stroke(color[0], color[1], color[2]);
			parent.strokeWeight(0.05f);
			parent.line(x, y, ox, ox);				// line only works with float 
		}
	}	
}
